<template>
    <div class="madp-marketing-thread">
        <div class="container">
            <mescroll-view class="scroll-view" :showMoreBtn="page.current * page.size < page.total" :total="page.total" @getMoreData="getMoreData">
                <div class="reminds-list">
                    <el-empty v-if="remindList.length < 1" :image="require('@/assets/img/no-todo.png')" description="暂无数据"></el-empty>
                    <template v-else>
                        <div class="reminds-item" v-for="(item, idx) in remindList" :key="idx">
                            <div @click="intoDetail(item)">
                                <div class="header">
                                    <img :src="item.avatar || $defaultAvatar" alt="" />
                                    <div class="info">
                                        <span class="text-one-ellipsis">{{ item.nickName }}</span>
                                        <span>{{ item.type == 1 ? '行内客户' : item.type == 2 ? 'CRM客户' : '访客' }}</span>
                                    </div>
                                </div>
                                <div class="desc">
                                    浏览了
                                    <span v-for="(item1, idx) in item.productTypeList" :key="idx">【{{ item1 }}】</span>
                                    {{ item.desc }}
                                </div>
                            </div>
                            <div class="btns">
                                <div class="btn" v-if="item.type != 0">
                                    <img src="@/assets/img/managerView/phone.png" alt="" srcset="" @click.stop="callPhone(item)" />
                                    <span>电话</span>
                                </div>
                                <div class="btn" v-if="item.type != 0 && item.wxExternalUserid">
                                    <img src="@/assets/img/managerView/wechat.png" alt="" srcset="" @click.stop="intoContacts(item)" />
                                    <span>微信</span>
                                </div>
                                <div class="btn" v-if="item.type == 0">
                                    <img src="@/assets/img/managerView/copy.png" alt="" srcset="" @click.stop="copyName(item)" />
                                    <span>复制</span>
                                </div>
                            </div>
                        </div>
                    </template>
                </div>
            </mescroll-view>
        </div>
        <back-btn />
    </div>
</template>
<script>
    import MescrollView from '@/components/material/mescroll-view.vue';
    import backBtn from '@/components/back-btn.vue';
    import managerViewApi from '@/api/manager-view.js';
    export default {
        components: { MescrollView, backBtn },
        data() {
            return {
                page: {
                    current: 1,
                    size: 10,
                    total: 0
                },
                remindList: []
            };
        },
        created() {},
        mounted() {},
        activated() {
            this.getMarketingCluePage();
        },
        methods: {
            getMoreData() {
                this.page.current++;
                this.getMarketingCluePage();
            },
            intoDetail(info) {
                this.$router.push({
                    path: '/managerView/marketing-detail',
                    query: {
                        info: JSON.stringify(info)
                    }
                });
            },
            callPhone(info) {
                if (this.$utils.isPcWeixin()) return;
                let a = document.createElement('a');
                a.setAttribute('href', `tel:${info.mobile}`);
                a.click();
            },
            intoContacts(info) {
                if (!info.wxExternalUserid) return;
                this.$wxApi.openEnterpriseChat({
                    externalUserIds: [info.wxExternalUserid]
                });
            },
            copyName(info) {
                let copyText = info.mobile || info.nickName;
                this.$copyText(copyText).then(
                    (e) => {
                        console.log('复制成功:', e);
                        this.$wxApi.navigateToAddCustomer();
                    },
                    (e) => {
                        this.$toast({ text: '复制失败', type: 'error' });
                        console.log('复制失败:', e);
                    }
                );
            },
            // 营销线索列表
            getMarketingCluePage() {
                managerViewApi
                    .getMarketingCluePage({
                        wxUserId: this.$store.state.vuex_wxUserId,
                        current: this.page.current,
                        size: this.page.size
                    })
                    .then((res) => {
                        if (this.page.current == 1) {
                            this.remindList = res.data.data.records;
                        } else {
                            this.remindList.push(...res.data.data.records);
                        }
                        this.page.total = res.data.data.total;
                    });
            }
        }
    };
</script>
<style scoped lang="scss">
    .madp-marketing-thread {
        background: #fafafa;
        .container {
            padding: 0 16px;
            .scroll-view {
                height: 100vh;
            }
            .reminds-list {
                padding-top: 16px;
                .reminds-item {
                    background: #ffffff;
                    box-shadow: 0px 3px 6px 0px rgba(181, 181, 181, 0.16);
                    border-radius: 8px;
                    padding: 16px;
                    margin-bottom: 10px;
                    display: flex;
                    flex-direction: column;
                    .header {
                        display: flex;

                        img {
                            width: 40px;
                            height: 40px;
                            border-radius: 50%;
                            margin-right: 8px;
                        }
                        .info {
                            flex: 1;
                            display: flex;
                            flex-direction: column;
                            justify-content: space-between;
                            :nth-child(1) {
                                font-size: 14px;
                                font-family: PingFangSC-Medium, PingFang SC;
                                font-weight: 500;
                                color: #202020;
                                width: 260px;
                            }
                            :nth-child(2) {
                                width: fit-content;
                                padding: 1px 4px;
                                background: #d5a874;
                                border-radius: 4px;
                                font-size: 10px;
                                font-family: PingFangSC-Medium, PingFang SC;
                                font-weight: 500;
                                color: #ffffff;
                            }
                            font-size: 14px;
                            font-family: PingFangSC-Medium, PingFang SC;
                            font-weight: 500;
                            color: #202020;
                        }
                    }
                    .desc {
                        margin-top: 8px;
                        font-size: 12px;
                        font-family: PingFangSC-Medium, PingFang SC;
                        font-weight: 500;
                        color: rgba(44, 44, 44, 0.8);
                        line-height: 17px;
                    }
                    .btns {
                        margin-top: 10px;
                        display: flex;
                        justify-content: flex-end;
                        .btn {
                            margin-left: 10px;
                            display: flex;
                            align-items: center;
                            border-radius: 13px;
                            border: 1px solid #ed5550;
                            padding: 5px 16px;
                            color: #ed5555;
                            img {
                                width: 16px;
                                height: 16px;
                                margin-right: 8px;
                            }
                        }
                    }
                }
            }
        }
    }
</style>
